@extends('admin.layouts.base')
@section('title','修改详情')
@section('pageHeader','修改详情')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            {{--提示信息弹出框--}}
            @include('admin.partials.errors')
            @include('admin.partials.success')
            {{--提示信息弹出框--}}

            {{--标题 开始--}}
            <div class="box box-success">
                <div class="box-header"><h1 class="box-title">修改详情 - {{ $data->pname }}</h1></div>
            </div>
            {{--标题 结束--}}

            <form action="" class="form-horizontal" method="post" enctype="multipart/form-data">

                <div class="box box-success">
                    <div class="box-header">
                        <h1 class="box-title">基本信息</h1>
                    </div>
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品名称 <b style="color:red">*</b></label>
                            <div class="col-sm-5">
                                <input type="text" name="name" class="form-control"
                                       value="{{ old('name') ?: $data->name }}"
                                       placeholder="最多30个字符" maxlength="30" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品链接 <b style="color:red">*</b></label>
                            <div class="col-sm-5">
                                <input type="text" name="link" class="form-control"
                                       value="{{ old('link') ?: $data->link }}"
                                       placeholder="最多30个字符" maxlength="150" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品LOGO <b style="color:red">*</b></label>
                            <div class="col-sm-5">
                                <input type="file" name="product_logo" >
                            </div>
                            <div class="col-sm-5">

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">原产品LOGO <b style="color:red">*</b></label>
                            <div class="col-sm-5">
                                <input type="image" name="product_logo_old" src="{{ old('product_logo_old') ?: $data->product_logo }}" style="height:80px;width:80px">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品简介 <b style="color:red">*</b></label>
                            <div class="col-sm-5">
                                <input type="text" name="product_introduction" class="form-control"
                                       value="{{ old('product_introduction') ?: $data->product_introduction }}"
                                       placeholder="最多60个字符" maxlength="500" required>
                            </div>
                        </div>
                    </div>
                </div>


                {{--token--}}
                <input type="hidden" name="_token" value="{{ csrf_token() }}">

                @include('admin.product._form')

                {{--提交按钮 开始--}}
                <div class="box box-widget">
                    <div class="box-footer">
                        <button class="btn btn-primary pull-right">提交</button>
                    </div>
                </div>
                {{--提交按钮 结束--}}

            </form>
        </div>
    </div>
@endsection

@section('js')
    <script>
        // 产品logo输入框自动显示已选图片
        $("input[name=product_logo]").change(function () {
            var obj = $(this).parents();
            var img = event.target.files[0];
            var id = 'logo';

            if (!img) {
                if ($('#' + id).length > 0) {
                    $('#' + id).remove()
                }
                return;
            }
            if (window.FileReader) {
                var im = document.createElement('img');
                im.id = id;
                if ($('#logo').length < 1) {
                    obj.append(im);
                }
                ;

                var fr = new FileReader();
                fr.onloadend = function (e) {
                    document.getElementById(id).src = e.target.result;
                    var imgObj = $('#' + id);
                    imgObj.css({
                        'width': '100px',
                        'height': '100px',
                    })
                };
                fr.readAsDataURL(img);
            }
        });
    </script>
@endsection